function minWindow(s: string, t: string): string {
    if (s.length === 0 || t.length === 0) return "";

    // 统计 t 中字符频率
    const tFreq = new Map<string, number>();
    for (const char of t) {
        tFreq.set(char, (tFreq.get(char) || 0) + 1);
    }

    // 所需唯一字符数
    const required = tFreq.size;

    // 滑动窗口指针和计数
    let left = 0, right = 0;
    let formed = 0;

    // 窗口字符频率
    const windowFreq = new Map<string, number>();

    // 结果信息：窗口长度, 左边界, 右边界
    const ans = [-1, 0, 0];

    while (right < s.length) {
        // 扩大右边界
        const char = s[right];
        windowFreq.set(char, (windowFreq.get(char) || 0) + 1);

        // 检查当前字符是否满足 t 中的要求
        if (tFreq.has(char) && windowFreq.get(char) === tFreq.get(char)) {
            formed++;
        }

        // 尝试收缩左边界
        while (left <= right && formed === required) {
            const currentLength = right - left + 1;

            // 更新最小窗口
            if (ans[0] === -1 || currentLength < ans[0]) {
                ans[0] = currentLength;
                ans[1] = left;
                ans[2] = right;
            }

            // 收缩窗口
            const leftChar = s[left];
            windowFreq.set(leftChar, windowFreq.get(leftChar)! - 1);

            if (tFreq.has(leftChar) && windowFreq.get(leftChar)! < tFreq.get(leftChar)!) {
                formed--;
            }

            left++;
        }

        right++;
    }

    return ans[0] === -1 ? "" : s.substring(ans[1], ans[2] + 1);
}